#include "CF.h"
#include "CF_NewWorkspaceDialog.h"
#include <QFileDialog>
#include <QMessageBox>

CF_NewWorkspaceDialog::CF_NewWorkspaceDialog(QWidget *parent)
	: QDialog(parent)
{
	ui.setupUi(this);
}

CF_NewWorkspaceDialog::~CF_NewWorkspaceDialog()
{

}

void CF_NewWorkspaceDialog::ok()
{
	QString& strName = getName();
	QString& strLocation = getLocation();

	if(strName.isEmpty())
	{
		QMessageBox::warning(this, tr("Warning"), tr("Please type the workspace name!!!"), QMessageBox::Ok);
		ui.nameEdit->setFocus();
		return;
	}
	
	if(strLocation.isEmpty())
	{
		QMessageBox::warning(this, tr("Warning"), tr("Please choose the directory where the workspace is created!!!"), QMessageBox::Ok);
		ui.locationEdit->setFocus();
		return;
	}

	QDialog::accept();
}

void CF_NewWorkspaceDialog::cancel()
{
	QDialog::reject();
}

void CF_NewWorkspaceDialog::locationButtonClicked()
{
	QFileDialog dlg(this);
	dlg.setFileMode(QFileDialog::Directory);
	dlg.setOption(QFileDialog::ShowDirsOnly);
	int ret = dlg.exec();
	if(ret==0)
		return;
	QStringList folderList = dlg.selectedFiles();
	ui.locationEdit->setText(folderList[0]);
}
